import router from './router'

const getToken = function() {
  return localStorage.getItem('X-Access-Token')
}

const whiteList = ['/login'] // no redirect whitelist

router.beforeEach(async(to, from, next) => {
  const hasToken = getToken()
  if (whiteList.indexOf(to.fullPath) !== -1) {
    next()
    return
  }
  if (hasToken) {
    next()
  } else {
    next({
      path: '/login'
    })
  }
})
